class Quadcopter:
    """四轴飞行器模型
    """
    def __init__(self, initial_height=0):
        # 重力加速度 m/s^2
        self.gravity = 9.81
        self.max_thrust = 2 * 9.81
        
        self.__height = initial_height
        self.__speed = 0

    def fly(self, thrust, delta_t=0.01):
        # if thrust > self.max_thrust:
        #     thrust = self.max_thrust
        # elif thrust < -self.max_thrust:
        #     thrust = -self.max_thrust
        
        # F = ma = mg = m ( a - g )
        acc = thrust - self.gravity
        # 速度 = 加速度 * delta_t
        self.__speed += acc * delta_t
        # 位移 = 速度 * delta_t
        self.__height += self.__speed * delta_t
    
        if self.__height < 0:
            self.__height = 0
        elif self.__height > 14:
            self.__height = 14

    def get_height(self):
        return self.__height

if __name__ == '__main__':
        
    # 示例用法
    quadcopter = Quadcopter()
    for i in range(10):
        quadcopter.fly(10)  # 模拟升力为10
        print("当前高度：", quadcopter.get_height())

    print("------------------------------")
    # 设置新高度
    quadcopter.__height = 20
    for i in range(10):
        quadcopter.fly(1.0)  # 模拟升力为9.0
        print("当前高度：", quadcopter.get_height())
        
    print("更新后的高度：", quadcopter.get_height())
